package cn.chinaflame.pagodas.api;

import cn.chinaflame.pagodas.constant.YanwuPayParam;
import cn.chinaflame.pagodas.enums.*;
import cn.chinaflame.pagodas.utils.HttpPostUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.math.BigDecimal;

/**
 * @author pengcheng.zhao
 */
public class YanwuPayAPI {

    /**
     * http接口，
     * 服务代码：203001
     * 调用身份：商户
     * 6.1 商户提交订单信息接口(收银台)
     *
     * @param customerIP
     * @param orderAmount
     * @param displayName
     * @param goodsName
     * @param goodsCount
     * @param payType
     * @param orgCode
     * @param directFlag
     * @param platformId
     * @param returnUrl
     * @param noticeUrl
     * @param remark
     * @return
     */
    public static String commitOrder(String customerIP, BigDecimal orderAmount, String displayName, String goodsName, Integer goodsCount,
                                     String payType, String orgCode, int directFlag, String platformId, String returnUrl, String noticeUrl, String remark) {
        JSONObject result = new JSONObject();
        try {
            HttpPostUtil.doPost(YanwuPayParam.PAYURL, "");
            result.put("responseCode", CodeEnum.SUCCESS.getCode());
            result.put("responseDesc", "");
        } catch (Exception e) {
            result.put("responseCode", CodeEnum.FAIL.getCode());
            result.put("responseDesc", "");
            e.printStackTrace();
        }
        return "";
    }


    /**
     * 接口类型：http
     * 服务代码：203002
     * 调用身份：商户
     * 6.2商户查询订单接口
     *
     * @param queryType
     * @param merOrderId
     * @return
     */
    public static String merchantQuery(QueryType queryType, String merOrderId) {

        JSONObject result = new JSONObject();
        try {
            HttpPostUtil.doPost(YanwuPayParam.PAYURL, "");
            result.put("responseCode", CodeEnum.SUCCESS.getCode());
            result.put("responseDesc", "");
            result.put("orderAmount", "");
            result.put("payAmount", "");
            result.put("acquiringTime", "");
            result.put("completeTime", "");
            result.put("merOrderId", "");
            result.put("platformDealId", "");
            result.put("stateCode", "");
        } catch (Exception e) {
            result.put("responseCode", CodeEnum.FAIL.getCode());
            result.put("responseDesc", "");
            e.printStackTrace();
        }

        return JSON.toJSONString(result);
    }

    /**
     * 6.3支付/退款/付款 通知信息
     * 接口类型：http/https
     * 服务代码：203003
     * 调用身份：平台
     *
     * @param merOrderId
     * @param stateCode
     * @param orderAmount
     * @param payAmount
     * @param acquiringTime
     * @param completeTime
     * @param platformDealId
     * @return
     */
    public static String asyncNotify(String merOrderId, StateCode stateCode, BigDecimal orderAmount, BigDecimal payAmount, String acquiringTime, String completeTime, String platformDealId) {
        JSONObject result = new JSONObject();
        try {
            HttpPostUtil.doPost(YanwuPayParam.PAYURL, "");
            result.put("responseCode", CodeEnum.SUCCESS.getCode());
            result.put("responseDesc", "");
        } catch (Exception e) {
            result.put("responseCode", CodeEnum.FAIL.getCode());
            result.put("responseDesc", "");
            e.printStackTrace();
        }
        return JSON.toJSONString(result);
    }

    /**
     * 6.4	商户退款申请
     * 接口描述	退款接口
     * 接口类型	http/https
     * 服务代码	203004
     * 调用身份	平台
     *
     * @param oldOrderId
     * @param refundAmount
     * @param noticeUrl
     * @return
     */
    public static String merchantRefund(String oldOrderId, BigDecimal refundAmount, String noticeUrl) {


        JSONObject result = new JSONObject();
        try {
            HttpPostUtil.doPost(YanwuPayParam.PAYURL, "");
            result.put("responseCode", CodeEnum.SUCCESS.getCode());
            result.put("responseDesc", "");
        } catch (Exception e) {
            result.put("responseCode", CodeEnum.FAIL.getCode());
            result.put("responseDesc", "");
            e.printStackTrace();
        }
        return JSON.toJSONString(result);
    }

    /**
     * 6.5接口名称   商户付款申请付款接口
     * 接口类型	http/https
     * 服务代码	203005
     * 调用身份	平台
     *
     * @param payeeName
     * @param payeeAccount
     * @param bankName
     * @param orgCode
     * @param orderAmount
     * @param channelCode
     * @param province
     * @param city
     * @param branche
     * @param remark
     * @param noticeUrl
     * @return
     */
    public static String merchantPayApply(String payeeName, String payeeAccount, String bankName, String orgCode, BigDecimal orderAmount, String channelCode, String province, String city, String branche, String remark, String noticeUrl) {
        JSONObject result = new JSONObject();
        try {
            HttpPostUtil.doPost(YanwuPayParam.PAYURL, "");


            result.put("responseCode", CodeEnum.SUCCESS.getCode());
            result.put("responseDesc", "");
        } catch (Exception e) {
            result.put("responseCode", CodeEnum.FAIL.getCode());
            result.put("responseDesc", "");
            e.printStackTrace();
        }
        return JSON.toJSONString(result);
    }

    /**
     * 6.6	商户提交订单信息(API收款)
     * 接口名称	商户提交订单信息
     * 接口类型	http
     * 服务代码	203006
     * 调用身份	商户
     *
     * @param customerIP
     * @param orderAmount
     * @param displayName
     * @param goodsName
     * @param goodsCount
     * @param payType
     * @param orgCode
     * @param directFlag
     * @param platformId
     * @param returnUrl
     * @param noticeUrl
     * @param remark
     * @return
     */
    public static String merchantCommitAPI(String customerIP, BigDecimal orderAmount, String displayName, String goodsName, int goodsCount, PayType payType, OrgCode orgCode, int directFlag, String platformId, String returnUrl, String noticeUrl, String remark) {

        JSONObject result = new JSONObject();
        ;
        try {
            if (true) {
                HttpPostUtil.doPost(YanwuPayParam.PAYURL, "");
                result.put("responseCode", CodeEnum.SUCCESS.getCode());
                result.put("responseDesc", "");
                result.put("codeUrl", "");
            } else {
                result.put("responseCode", CodeEnum.FAIL.getCode());
                result.put("responseDesc", "");
            }
        } catch (Exception e) {
            result.put("responseCode", CodeEnum.FAIL.getCode());
            result.put("responseDesc", "");
            e.printStackTrace();
        }
        return JSON.toJSONString(result);
    }

}
